package com.kitty.game.xmd;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.confirm.service.handler.ConfirmHandler;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.team.message.ReqConfirmResult;
import com.kitty.mina.message.MessagePusher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class XianMoConfirmHandler extends ConfirmHandler {
    @Autowired
    EquipService equipService;

    @Autowired
    RoleService roleService;
    @Override
    public void handleConfirmResult(Role role, ReqConfirmResult reqConfirmResult) {
        if ("1".equals(reqConfirmResult.getSelect())) {
            SpringUtils.getBean(XianMoConfirmHandler.class).XMZH(role, role.getChildInfo().getXianmoqiehuan());
        }
    }

    public void XMZH(Role role,int type){
        coagulationXmdInfo coagulation = new coagulationXmdInfo();
        coagulation.setUpgrade_type((byte)type);
        MessagePusher.pushMessage(role, coagulation);
        RoleEquip roleEquip =  equipService.getRoleEquipByName(role,"天星石");
        equipService.delEquipNum(role,roleEquip,3);
        transXianmo(role,(byte)type);
    }


    // 仙魔转换
    private void transXianmo(Role role, byte type) {
        if (type==3) {
            this.roleService.getChild(role, (byte)3);
        } else {
            this.roleService.getChild(role, (byte)4);
        }
        SpringUtils.getBroadcastService().sendUpdateAppear(role);
        this.roleService.substractChargeScore(role, 0);
    }
}
